//
//  SettingViewController.m
//  ApeExample
//
//  Created by Eton on 2017/7/28.
//  Copyright © 2017年 王-庭协. All rights reserved.
//

#import "SettingViewController.h"
#import "SettingCell.h"
#import "SettingPresenter.h"

@interface SettingViewController ()<UITableViewDataSource,UITableViewDelegate,SettingCellDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) SettingPresenter *presenter;

@end

@implementation SettingViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    self.title = @"设置";
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupData];
    
    [self setupView];
}

#pragma mark - setup

- (void)setupData{
    self.presenter = [[SettingPresenter alloc] init];
}

- (void)setupView{
    
}


#pragma mark - SettingPresenterDelegate

#pragma mark - Action
- (IBAction)exitAction:(id)sender {
//    [UIAlertView alertViewWithTitle:@"提醒" message:@"您确定要退出客户端吗？" cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定"] onDismiss:^(int buttonIndex) {
//        [kGlobalData logoutWithFail:nil];
//    } onCancel:^{
//        
//    }];
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    return [[self presenter] listArray].count;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    SettingListModel * listModel = [[self presenter] listArray][section];
    return [listModel interiorArray].count;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 55.0;
}

//- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
//    return 10;
//}
//
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
//    return nil;
//}
//
//- (CGFloat )tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//    return 1;
//}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdentifier = @"SettingCell";
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [SettingCell tx_loadFromNib];
    }
    cell.delegate = self;
    SettingListModel * listModel = [[self presenter] listArray][indexPath.section];
    SettingModel * model = listModel.interiorArray[indexPath.row];
    if ([model.title isEqualToString:SettingTableName_Push]) {
        model.switchOn = [UIApplication tx_accessNotification];
    }
    cell.model = listModel.interiorArray[indexPath.row];
    //    cell.delegate = self;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SettingListModel * listModel = [[self presenter] listArray][indexPath.section];
    SettingModel * model = listModel.interiorArray[indexPath.row];
    if ([model.title isEqualToString:SettingTableName_Push]) {
        
    }else if ([model.title isEqualToString:SettingTableName_Password]) {
//        [self pushViewControllerClass:ChangePasswordViewController.class];
    }
}


//- (void)selectMessagePush:(BOOL)isPush{
//    NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
//    
//    if([[UIApplication sharedApplication] canOpenURL:url]) {
//        [[UIApplication sharedApplication] openURL:url];
//    }
//}
@end
